<?php
header("Content-Type: text/html; charset=utf-8");

$user = $_POST['username'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];

if ($pass1 != $pass2) {
    die('<script>alert("两次密码不一致!");window.location.href = "zhuce.html";</script>');
}

require 'connect.php';

echo "=====================";

$sql = 'select username from user where username="' . $user . '"; ';
$result = mysqli_query($link, $sql);
if ($result->num_rows == 1) {
    mysqli_close($link);
    die('<script>alert("用户名已存在!");window.location.href = "zhuce.html";</script>');
} else {
    $sql2 = "insert user(username,password,reg_time) values('$user','$pass1',CURRENT_TIMESTAMP());";
    $result2 = mysqli_query($link, $sql2);
    if ($result2) {
        echo '<script>alert("注册成功");window.location.href = "login.html";</script>';
    } else {
        echo '<script>alert("请求异常!");window.location.href = "zhuce.html";</script>';
    }
}

mysqli_close($link);
